<%--
  Created by IntelliJ IDEA.
  User: 许正雄
  Date: 2021/12/7
  Time: 17:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>后台管理</title>
    <link type="text/css" rel="stylesheet" href="/static/css/style.css" />
    <script type="text/javascript" src="/static/scripts/function-manage.js"></script>
    <script type="text/javascript" src="/static/jquery3.6.0.js"></script>
</head>
<body>
<%@include file="/manage/head.jsp"%>
<div id="position" class="wrap">
</div>
<div id="main" class="wrap">
    <%@include file="/manage/left.jsp"%>
    <div class="main">
        <h2>管理员管理</h2>
        <div>
            <form action="selectAdminPage" method="post" id="frm">
                <input type="hidden" name="pageNo" id="pageNo" value="${adminIPage.current}"/>
                <input type="hidden" name="pageSize" id="pageSize" value="${adminIPage.size}"/>
               用户名： <input type="text" id="userName" name="userName" value="${admin.userName}" placeholder="请输入账号"/>
                真实姓名：<input type="text" id="fullName" name="fullName" value="${admin.fullName}" placeholder="请输入姓名"/>
                <button type="submit" onclick="cl()">查询</button>
            </form>
        </div>
        <div class="manage">
            <table class="list">
                <tr>
                    <th>ID</th>
                    <th>用户名</th>
                    <th>密码</th>
                    <th>姓名</th>
                    <th>备注</th>
                    <th>操作</th>
                </tr>
            <c:forEach items="${adminIPage.records}" var="user" varStatus="stu">
                <tr>
                    <td class="first w4 c">${stu.index+1} <input type="hidden" value="${user.id}"/></td>
                    <td class="w1 c">${user.userName}</td>
                    <td class="w2 c">${user.password}</td>
                    <td class="w3 c">${user.fullName}</td>
                    <td class="w4 c">${user.remark}</td>
                    <td class="w1 c"><a id="xg" href="../manage/queryUserById?id=${user.id}">修改</a> <button  type="button" onclick="Deleteuser('${user.idStr}')" id="del">删除</button></td>
                </tr>
            </c:forEach>
                <tfoot>
                <tr>
                    <td colspan="6">
                        每页<select name="size" id="spageSize">
                        <option value="1" <c:if test="${adminIPage.size==1}">selected</c:if>>1</option>
                        <option value="2" <c:if test="${adminIPage.size==2}">selected</c:if>>2</option>
                        <option value="3"<c:if test="${adminIPage.size==3}">selected</c:if>>3</option>
                    </select>行&nbsp;&nbsp;&nbsp;
                        <a href="javascript:goToPage(1)">首页</a>&nbsp;&nbsp;&nbsp;
                        <c:if test="${adminIPage.hasPrevious()}">
                            <a href="javascript:goToPage(${adminIPage.current-1})">上一页</a>&nbsp;&nbsp;&nbsp;
                        </c:if>
                        <c:if test="${!adminIPage.hasPrevious()}">
                            <a href="javascript:alert('已经是第一页了！')">上一页</a>&nbsp;&nbsp;&nbsp;
                        </c:if>
                        <c:if test="${adminIPage.hasNext()}">
                        <a href="javascript:goToPage(${adminIPage.current+1})">下一页</a>&nbsp;&nbsp;&nbsp;
                        </c:if>
                        <c:if test="${!adminIPage.hasNext()}">
                            <a href="javascript:alert('已经是最后一页了！')">下一页</a>&nbsp;&nbsp;&nbsp;
                        </c:if>
                        <a href="javascript:goToPage(${adminIPage.pages})">末页</a>
                        第${adminIPage.current}页/共${adminIPage.pages}页
                    </td>
                </tr>
                </tfoot>
            </table>
        </div>
    </div>
    <div class="clear"></div>
</div>
<div id="footer">
</div>
</body>
<script type="text/javascript">
    function goToPage(ret) {
        $("#pageNo").val(ret);
        $("#frm").submit();
    }
    $(function () {
        $("#spageSize").change(function () {
            $("#pageSize").val($(this).val());
            $("#pageNo").val(1);
            $("#frm").submit();
        })
    })
    function cl() {//设定每次查询第一页
        $("#pageNo").val(1);
    }

    // $(function () {
    //     $("#spageSize").change(function () {
    //         $("#pageSize").val($(this).val());
    //         $("#frm").submit();
    //     })
    // })
    function Deleteuser(uid) {
            let msg="是否确定要删除该数据？？？";
            if(confirm(msg)){
                $.ajax({
                    url:"deleteUserById",
                    type:"post",
                    data:"id="+uid,
                    success:function (ret) {
                        if (ret*1==1){
                            alert("删除成功！！！");
                            $(location).attr("href","../manage/selectAdminPage");
                        }
                    }
                })
                return true;
            }else {
                return false;
            }
    }
</script>
</html>

